﻿import { message} from 'antd';
import {history} from '@umijs/max'
import { getToken } from '@/store/token'
export const requestConfig = {
  // 请求拦截器
  requestInterceptors: [
    (config) => {
      // 拦截请求配置，进行个性化处理。
      const url = config?.url;
      let toekn = getToken()
      config.headers = {
        Authorization: toekn
      }
      return { ...config, url };
    },
  ],
  
  // 响应拦截器
  responseInterceptors: [
    (response) => {
      if(response.status != 200){
        message.error("未知异常！")
        return response;
      }
      // 拦截响应数据，进行个性化处理
      const { data } = response;
      //对于登录异常的处理
      if(data?.code === "401"){
        history.push("/login")
      }
      if (data?.success === false) {
        message.error(data.msg);
      }
      return response;
    },
  ],
};
